package com.ruoyi.bnt.controller;

import java.util.List;

import com.ruoyi.common.utils.uuid.UUID;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bnt.domain.BntSpecialcolumn;
import com.ruoyi.bnt.service.IBntSpecialcolumnService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专栏Controller
 * 
 * @author yyj
 * @date 2020-09-29
 */
@Controller
@RequestMapping("/bnt/specialcolumn")
public class BntSpecialcolumnController extends BaseController
{
    private String prefix = "bnt/specialcolumn";

    @Autowired
    private IBntSpecialcolumnService bntSpecialcolumnService;

    @RequiresPermissions("bnt:specialcolumn:view")
    @GetMapping()
    public String specialcolumn()
    {
        return prefix + "/specialcolumn";
    }

    /**
     * 查询专栏列表
     */
    @RequiresPermissions("bnt:specialcolumn:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BntSpecialcolumn bntSpecialcolumn)
    {
        startPage();
        List<BntSpecialcolumn> list = bntSpecialcolumnService.selectBntSpecialcolumnList(bntSpecialcolumn);
        return getDataTable(list);
    }

    /**
     * 导出专栏列表
     */
    @RequiresPermissions("bnt:specialcolumn:export")
    @Log(title = "专栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BntSpecialcolumn bntSpecialcolumn)
    {
        List<BntSpecialcolumn> list = bntSpecialcolumnService.selectBntSpecialcolumnList(bntSpecialcolumn);
        ExcelUtil<BntSpecialcolumn> util = new ExcelUtil<BntSpecialcolumn>(BntSpecialcolumn.class);
        return util.exportExcel(list, "specialcolumn");
    }

    /**
     * 新增专栏
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存专栏
     */
    @RequiresPermissions("bnt:specialcolumn:add")
    @Log(title = "专栏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BntSpecialcolumn bntSpecialcolumn)
    {
        if(bntSpecialcolumn.getId() == null || bntSpecialcolumn.getId().isEmpty())
            bntSpecialcolumn.setId(UUID.randomUUID().toString());
        return toAjax(bntSpecialcolumnService.insertBntSpecialcolumn(bntSpecialcolumn));
    }

    /**
     * 修改专栏
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BntSpecialcolumn bntSpecialcolumn = bntSpecialcolumnService.selectBntSpecialcolumnById(id);
        mmap.put("bntSpecialcolumn", bntSpecialcolumn);
        return prefix + "/edit";
    }

    /**
     * 修改保存专栏
     */
    @RequiresPermissions("bnt:specialcolumn:edit")
    @Log(title = "专栏", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BntSpecialcolumn bntSpecialcolumn)
    {
        return toAjax(bntSpecialcolumnService.updateBntSpecialcolumn(bntSpecialcolumn));
    }

    /**
     * 删除专栏
     */
    @RequiresPermissions("bnt:specialcolumn:remove")
    @Log(title = "专栏", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bntSpecialcolumnService.deleteBntSpecialcolumnByIds(ids));
    }

    @RequiresPermissions("bnt:specialcolumn:add")
    @GetMapping("/info/{infoId}")
    public String infoId(@PathVariable("infoId") String infoId, ModelMap mmap)
    {
        mmap.put("infoId", infoId);
        return "bnt/specialcolumn/specialcolumninfo/specialcolumninfo";
    }
}
